/**
 * 报警管理
 */
import * as React from "react";
import {message, Tabs} from "antd";
import moment from "moment";

import AlarmManageCondition, {AlarmManageConditionParam} from "./compontents/Condition";
import {getNetWorkData} from "../../../../utils/common";
import {alarmTypeUrl} from "./compontents/serverApi";
import AlarmManageTable, {AlarmManageTableParam} from "./compontents/Table";
import "./index.less";

export interface AlarmManageProps {}

export interface AlarmManageState {}

const {TabPane} = Tabs;

class AlarmManage extends React.Component<AlarmManageProps, AlarmManageState> {
    private alarmTypeData: [] = [];
    private notTableParam: AlarmManageTableParam = {
        isHandle: "0",
        alarmType: 0,
        start: moment().subtract(7, 'day').startOf("day").valueOf(),
        end: moment().endOf("day").valueOf(),
    };
    private yesTableParam: AlarmManageTableParam = {
        isHandle: "1",
        alarmType: 0,
        start: 0,
        end: 0,
    };

    render() {
        return (
            <div className="AlarmManage">
                <Tabs defaultActiveKey="1">
                    <TabPane tab="未处理" key="1">
                        <AlarmManageCondition
                            alarmTypeData={this.alarmTypeData}
                            query={(paramJson: AlarmManageConditionParam) => {this.queryNot(paramJson);}}
                        />
                        <div className="subject">
                            <AlarmManageTable paramJson={this.notTableParam}/>
                        </div>
                    </TabPane>
                    <TabPane tab="已处理" key="2">
                        <AlarmManageCondition
                            alarmTypeData={this.alarmTypeData}
                            query={(paramJson: AlarmManageConditionParam) => {this.queryYes(paramJson);}}
                        />
                        <div className="subject">
                            <AlarmManageTable paramJson={this.yesTableParam}/>
                        </div>
                    </TabPane>
                </Tabs>
            </div>
        );
    }
    /**钩子函数 */
    componentWillMount() {
        this.init();
    }
    //初始化
    init() {
        getNetWorkData(alarmTypeUrl, null, this, (result) => {
            if (result.success) {
                this.alarmTypeData = result.data;
                this.forceUpdate();
            }
        });
    }
    //未处理
    queryNot(paramJson: AlarmManageConditionParam) {
        if (paramJson.start === 0 || paramJson.end === 0) {
            message.info("请选择时间！");
            return ;
        }
        this.notTableParam = {
            isHandle: "0",
            alarmType: paramJson.alarmType,
            start: paramJson.start,
            end: paramJson.end,
        };
        this.forceUpdate();
    }
    //已处理
    queryYes(paramJson: AlarmManageConditionParam) {
        if (paramJson.start === 0 || paramJson.end === 0) {
            message.info("请选择时间！");
            return ;
        }
        this.yesTableParam = {
            isHandle: "1",
            alarmType: paramJson.alarmType,
            start: paramJson.start,
            end: paramJson.end,
        };
        this.forceUpdate();
    }
}
export default AlarmManage;